home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-01-13 | 1.6 KB | 46 lines | [TEXT/EDIT] |
- ; Takes a string of hex characters representing mixed byte code
- ; and Motorola 68000 machine code,
- ; and an arbitrary number of constants referred to
- ; by the code, and encapsulates the code in a Scheme procedure,
- ; which it returns.
- ;
- ; The string should probably look like:
- ;
- ; 95n8 args= n8 ;byte code
- ; 6300 native2 ;byte code
- ; <native code>
- ; 49FA0004 LEA *+4,A4
- ; 4ED6 JMP (A6)
- ; 98 restore ;byte code
-
- (define hex2
- (lambda (c1 c2)
- (+ (* 16 (hex->int c1)) (hex->int c2))))
-
- (define hex->int
- (lambda (c)
- (cond ((and (char>=? c #\0) (char<=? c #\9))
- (- (char->integer c) (char->integer #\0)))
- ((and (char>=? c #\a) (char<=? c #\f))
- (+ (- (char->integer c) (char->integer #\a)) 10))
- ((and (char>=? c #\A) (char<=? c #\F))
- (+ (- (char->integer c) (char->integer #\A)) 10))
- (else ?))))
-
-
- (define wrap-code
- (lambda (code . constants)
- (do ((code (->bytevector code))
- (bcode (make-bytevector (quotient (string-length code) 2)))
- (i 0 (+ i 1))
- (j 0 (+ j 2))
- (n (quotient (string-length code) 2)))
- ((=? i n)
- (->procedure
- (list (cons bcode (list->vector (cons '() constants))))))
- (bytevector-set! bcode
- i
- (hex2 (bytevector-ref code j)
- (bytevector-ref code (1+ j)))))))
-
-